﻿using System.Net;
using System.Web.Mvc;

namespace IterationLife.Extensions.MvcApi
{
    public class MvcApiAuthorizeAttribute: AuthorizeAttribute
    {
        protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
        {
            return httpContext.User.Identity.IsAuthenticated;
        }

        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            filterContext.Result = new JsonResult
            {
                Data = new MvcApiResult<object> {Message = "没有访问权限"},
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                
            };
            filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
        }
    }
}
